﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using T.FAS.Runtime.Base.Dao;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Base.Service
{
    public class FunctionTreeService
    {
        readonly FunctionTreeDao functionTreeDao;

        public FunctionTreeService()
        {
            string wrpRouterDb = ConfigurationManager.AppSettings["FAS_SysMenuDataBase"];
            if (string.IsNullOrEmpty(wrpRouterDb))
            {
                wrpRouterDb = "TFAS";
            }

            functionTreeDao = new FunctionTreeDao(wrpRouterDb);
        }
        /// <summary>
        /// 获取产品版本下关键应用
        /// </summary>
        /// <returns></returns>
        public List<Function> GetApplications(string productVersionID, string subSystemID)
        {
            return functionTreeDao.GetApplications(productVersionID, subSystemID);
        }
        /// <summary>
        /// 获取关键应用下模块
        /// </summary>
        /// <returns></returns>
        public List<Function> GetModules(Function app)
        {
            List<Function> modules = functionTreeDao.GetModules(app).OrderBy(t => t.Code).ToList();
            foreach (var module in modules)
            {
                module.Nodes = functionTreeDao.GetMenuGroup(module);
            }
            return modules;
        }
        /// <summary>
        /// 获取关键应用名称
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        public string GetApplicationSortName(string appId, string subSystemID)
        {
            return functionTreeDao.GetApplicationSortName(appId, subSystemID);
        }
        /// <summary>
        /// 获取功能组名称
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public string GetGroupName(string groupID, string productVersionID)
        {
            return functionTreeDao.GetGroupName(groupID, productVersionID);
        }
        #region 弃用
        public List<Function> GetFunctionTree()
        {
            return new List<Function>();
        }
        /// <summary>
        /// 获取功能组
        /// </summary>
        /// <returns></returns>
        public List<Function> GetMenuGroup(Function module)
        {
            return new List<Function>();
        }
        #endregion
    }
}
